﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcMusicStore.Models;
using MVCQuick.Framework.Repository;

namespace MvcMusicStore.Controllers
{
    public class StoreController : Controller
    {
        private IRepository repository;

        public IRepository Repository
        {
            get
            {
                return repository;
            }
            set
            {
                repository = value;
            }
        }

        //
        // GET: /Store/

        public ActionResult Index()
        {
            var genres = repository.Query<Genre>().ToList();

            return View(genres);
        }

        //
        // GET: /Store/Browse?genre=Disco

        public ActionResult Browse(string genre)
        {
            // Retrieve Genre and its Associated Albums from database           
            var genreModel =
                repository.Query<Genre>()
                .Where(x => x.Name == genre)
                .SingleOrDefault();            

            return View(genreModel);
        }

        //
        // GET: /Store/Details/5

        public ActionResult Details(int id)
        {
            var album = repository.Get<Album>(id);      

            return View(album);
        }

        //
        // GET: /Store/GenreMenu

        [ChildActionOnly]
        public ActionResult GenreMenu()
        {
            var genres = repository.Query<Genre>().ToList();

            return PartialView(genres);
        }

    }
}